package com.baimawangzi.recovery.servlet.activity;

import com.baimawangzi.recovery.bean.Activity;
import com.baimawangzi.recovery.bean.PageBean;
import com.baimawangzi.recovery.service.impl.ActivityServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/activitylist.do")
public class ActivityListServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ActivityServiceImpl activityService = new ActivityServiceImpl();
        //默认从第一页开始每页6条
        int page=1;
        int size=6;
        String spage = req.getParameter("page");
        if(null!=spage){
            System.out.println("spage"+spage);
            page=Integer.parseInt(spage);
        }
        String ssize = req.getParameter("size");
        if(null!=ssize){
            size=Integer.parseInt(ssize);
        }

        PageBean<Activity> pageBean = activityService.getPageBean(page, size);
        System.out.println(pageBean);
        req.setAttribute("pageBean",pageBean);
        req.getRequestDispatcher("activity_list.jsp").forward(req,resp);

    }
}
